import { constantRoutes, asyncRoutes } from '@/router'
const state = {
  routes: constantRoutes
}

const mutations = {
  setRoutes(state, newRoutes) {
    state.routes = [...constantRoutes, ...newRoutes]
  }
}

const actions = {
  filterRoutes({ commit }, menus) {
    const routes = []
    menus.forEach(key => {
      routes.push(...asyncRoutes.filter(item => item.name === key)) // 去获取回来的权限中 到动态路由
      // 里面去查找 如果 找到了 说明 当前用户这个权限 把这个路由对象 push到数组里面去 更改state里面的routes
    })
    commit('setRoutes', routes) // 更改 state里面的路由
    return routes
  }
}
export default {
  namespaced: true,
  state,
  mutations,
  actions
}
